package com.jlu.config;

import com.jlu.properties.DemoProperties;
import com.jlu.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(DemoProperties.class)//开启配置项的支持
@ConditionalOnProperty(//设置配置项的属性，是否打开，前缀
        prefix = "demo",
        name = "isopen",
        havingValue = "true"
)
public class DemoConfig {
  @Autowired
  private DemoProperties demoProperties;

  @Bean(name = "demo")
  public DemoService demoService(){
    return new DemoService(demoProperties.getSayWhat(), demoProperties.getToWho());
  }
}
